package www.sofn.com.order;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import www.sofn.com.domain.R;
import www.sofn.com.order.domain.query.OrderInfoQuery;
import www.sofn.com.order.domain.vo.CreateGoodsOrderVo;
import www.sofn.com.order.domain.vo.CreateShoppingCartGoodsOrderVo;
import www.sofn.com.order.domain.vo.OrderInfoVO;

import javax.xml.bind.ValidationException;
import java.util.List;

@RestController
@RequestMapping("goods_order")
@Tag(name ="订单")
public class GoodsOrderController {

    @Resource
    private GoodsOrderService orderService;


    @Operation(summary = "查询所有订单")
    @GetMapping
    public R<List<OrderInfoVO>> list(OrderInfoQuery query)  {
        return R.ok(orderService.finalOrderInfo( query));
    }

    @Operation(summary = "订单数量")
    @GetMapping("/count")
    public R<List<OrderInfoVO>> getOrderCount()  {
        return R.ok(orderService.getOrderCount( ));
    }



    @Operation(summary = "创建订单")
    @PostMapping("create_order")
    public R createOrder(@RequestBody @Validated() CreateGoodsOrderVo vo) throws ValidationException {
        orderService.createOrder(vo);
        return R.ok();
    }


    @Operation(summary = "创建购物车订单")
    @PostMapping("create_shopping_cart_order")
    public R createShoppingCartOrder(@RequestBody @Validated() CreateShoppingCartGoodsOrderVo vo) throws ValidationException {
        orderService.createShoppingCartOrder(vo);
        return R.ok();
    }
}
